package com.fadis.data;

import com.fadis.data.bloomfilter.BloomFilter;

public class FBloomFilter {

    public static BloomFilter create(){
        BloomFilter bf = new BloomFilter(16, 16);
        return bf;
    }

    public static boolean add(BloomFilter bf, String s){
        if(bf == null) return false;
        boolean present = bf.isPresent(s);
        bf.add(s); // 因为能误判，导致没见过的说见过，所以总是覆盖一下
        return present;
    }

    public static boolean[] madd(BloomFilter bf, String...s){
        boolean[] r = new boolean[s.length];
        if(bf == null) {
            for (int i = 0; i < r.length; i++) {
                r[i] = false;
            }
            return r;
        }
        for (int i = 0; i < s.length; i++) {
            r[i] = add(bf, s[i]);
        }
        return r;
    }

    public static boolean exists(BloomFilter bf, String s){
        if(bf == null) return false;

        return bf.isPresent(s);
    }

    public static boolean[] mexists(BloomFilter bf, String...s){
        boolean[] r = new boolean[s.length];
        if(bf == null) {
            for (int i = 0; i < r.length; i++) {
                r[i] = false;
            }
            return r;
        }
        for (int i = 0; i < s.length; i++) {
            r[i] = bf.isPresent(s[i]);
        }

        return r;
    }


}
